package com.example.service.impl;

import com.alibaba.nacos.common.utils.MD5Utils;
import com.example.entity.Page.MyPageHelper;
import com.example.entity.Page.PageRequest;
import com.example.entity.Staffs;
import com.example.mapper.StaffsMapper;
import com.example.result.CommonResult;
import com.example.service.StaffsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: tobed
 * @date: 2022/11/14
 * @time: 11:19
 */
@Service
public class StaffsServiceImpl implements StaffsService {

    @Autowired
    StaffsMapper staffsMapper;

    @Override
    public CommonResult list(Staffs staffs, PageRequest pageRequest) {
        MyPageHelper.startPage(pageRequest);
        List<Staffs> list = staffsMapper.list(staffs);
        return CommonResult.ok(MyPageHelper.getPageResult(list));
    }

    /*重置密码*/
    @Override
    public CommonResult rest(Integer id) {
        String password = "e10adc3949ba59abbe56e057f20f883e\n";
        int i = staffsMapper.rest(id,password);
        if (i!=0){
            return CommonResult.ok();
        }else{
            return CommonResult.fail(888,"网络异常");
        }
    }

    /*修改用户状态*/
    @Override
    public CommonResult updateSTatus(Integer id, int status) {
        int i = staffsMapper.updateSTatus(id,status);
        if (i!=0){
            return CommonResult.ok();
        }else{
            return CommonResult.fail(888,"网络异常");
        }
    }
}
